<template>
	<view>
		<!-- 搜索热区组件导入 -->
		<SearchLink></SearchLink>
		<!--主体-->
		<view class="content" v-if="categoryList[activeIndex]">
			<view class="left">
				<view class="cate1" :class="{active:index===activeIndex}" v-for="(cate1,index) in categoryList" :key="index" @click="activeIndex=index">
					{{cate1.cat_name}}
				</view>
			</view>
			<view class="right">
				<image src="../../static/images/titleImage.png"></image>
				<!-- 二级分类 -->
				<view class="cate2" v-for="(cate2,index2) in categoryList[activeIndex].children " :key="index2">
					<view class="title">
						/<text>{{cate2.cat_name}}</text>/
					</view>
					<!-- 三级分类列表 -->
					<view class="cate3-wrapper">
						<view class="cate3" v-for="(cate3,index3) in cate2.children " :key="index3" @click="toSearchList(cate3.cat_name)">
							<image :src="cate3.cat_icon" mode=""></image>
							<view class="">
								<text>{{cate3.cat_name}}</text>
							</view>

						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import SearchLink from "@/components/SearchLink.vue"
	export default {
		components: {
			SearchLink
		},
		data() {
			return {
				// 让左侧栏默渲染的时候下标0为默认样式
				activeIndex: 0,
				// 分类列表数组
				categoryList: []

			}
		},
		onLoad() {
			this.getCategoryList()

		},
		methods: {
			// 请求分类列表
			getCategoryList() {
				wx.request({
					url: 'https://www.uinav.com/api/public/v1/categories',
					success: res => {
						console.log(res)
						// if (res.data.meta.status === 200) {
						// 	this.swiperdata = res.data.message
						// }
						//可以使用es6的解构语法
						let {
							meta,
							message
						} = res.data;
						if (meta.status === 200) {
							this.categoryList = message;
						}
					}
				})
			},
			toSearchList(catName) {
				uni.navigateTo({
					url: '/pages/search_list/search_list?catName=' + catName,
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.content {
		color: #333;
		display: flex;
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0;
		top: 100rpx;

		.left {
			width: 198rpx;
			overflow: auto;

			.cate1 {
				height: 100rpx;
				line-height: 100rpx;
				text-align: center;
				background-color: #f4f4f4;
				border-bottom: solid 1rpx #eee;
				box-sizing: border-box;

			}

			.active {
				background-color: #fff;
				color: #eb4450;
				position: relative;
				font-weight: bold;

				&::before {
					position: absolute;
					content: '';
					width: 8rpx;
					height: 60rpx;
					top: 20rpx;
					left: 0;
					background-color: #eb4450;
				}
			}
		}

		.right {
			flex: 1;
			padding: 20rpx 16rpx 0;
			overflow: auto;

			>image {
				width: 520rpx;
				height: 180rpx;

			}

			.cate2 {
				margin-bottom: 40rpx;

				.title {
					text-align: center;
					color: #e0e0e0;
					height: 110rpx;
					line-height: 110rpx;

					text {
						color: #333;
						margin: 0 30rpx;
					}
				}
			}

			.cate3-wrapper {
				display: flex;
				flex-wrap: wrap;
			}

			.cate3 {
				margin-bottom: 20rpx;
				width: 33.3%;
				text-align: center;

				image {
					width: 120rpx;
					height: 120rpx;
				}
			}
		}

	}
</style>
